<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>

<body>
    <div id="app">
        <el-container>
            <el-header></el-header>
            <el-main>
                <el-row type="flex" class="row-bg" justify="space-around">
                    <el-col :span="6">
                        <div class="grid-content bg-purple"></div>
                    </el-col>
                    <el-col :span="6">
                        <div class="grid-content bg-purple-light">
                            <h3>用户注册</h3>
                            <el-form :label-position="labelPosition" label-width="80px" :model="formLabelAlign">
                                <h2></h2>
                                <el-form-item label="账号">
                                    <el-input v-model="formLabelAlign.name"></el-input>
                                </el-form-item>
                                <el-form-item label="密码">
                                    <el-input v-model="formLabelAlign.region" type="password"></el-input>
                                </el-form-item>
                                <el-form-item label="确认密码">
                                    <el-input v-model="formLabelAlign.type" type="password"></el-input>
                                </el-form-item>
                                <el-form-item>
                                    <el-button type="primary" @click="test()">立即创建</el-button>
                                    <el-button @click="back()">取消</el-button>
                                </el-form-item>
                            </el-form>
                        </div>
                    </el-col>
                    <el-col :span="6">
                        <div class="grid-content bg-purple"></div>
                    </el-col>
                </el-row>
            </el-main>
            <el-footer></el-footer>
        </el-container>
    </div>
</body>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<!--导入jquery的库-->
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>

<script>
    new Vue({
        el: '#app',
        data: function() {
            return {
                labelPosition: 'left',
                formLabelAlign: {
                    name: '',
                    region: '',
                    type: ''
                }
            }
        },
        methods: {
            isEmpty: function(obj) {
                if (typeof obj == "undefined" || obj == null || obj == "") {
                    return false;
                } else {
                    return true;
                }
            },
            test: function() {

                var acc = this.formLabelAlign.name
                var pwd = this.formLabelAlign.region
                var ack = this.formLabelAlign.type
                console.log(this.isEmpty(acc))
                if (!this.isEmpty(acc)) {
                    alert("账号不能为空")
                    return;
                }
                if (!this.isEmpty(pwd) || !this.isEmpty(pwd)) {
                    alert("输入的密码不能为空")
                    return;
                }
                if (pwd != ack) {
                    alert("两次输入的密码不一致")
                    return;
                }


                console.log("this is the test")
                    /**
                     * 向发送请求
                     */
                $.ajax({
                    type: "post",
                    url: "http://localhost:8080/manager/register",
                    data: {
                        "account": acc,
                        "password": pwd
                    },
                    contentType: "application/x-www-form-urlencoded",
                    dataType: "json",
                    success: function(data) {
                        console.log(data);
                        if (data == true) {
                            window.location.assign("login.html")
                            alert("注册成功")
                        } else {
                            alert("注册失败")
                        }
                    }
                })
            }
        }
    })
</script>

</html>